﻿using AnesSystem.Models;
using AnesSystem.Services;
using MongoDB.Bson;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Common;
using System.Windows;

namespace AnesSystem.ViewModels
{
    public class SecheduledListCtrlViewModel : BaseViewModel<SecheduledListCtrlViewModel>
    {

        #region Variables
        private string _curRoomId;
        private IEnumerable<PatientLinkModel> _scheduledList;
        private IEnumerable<PatientLinkModel> _displayScheduledList;
        private string _curRoomText;
        private PatientLinkModel _selectedP;
        
        private string hospital_code;

        #endregion

        #region Constructor
        public SecheduledListCtrlViewModel()
        {
            _displayScheduledList = new List<PatientLinkModel>();
            Hospital_code = HospitalConfig.Instance.CurrentHospital.HospitalCode;
            //InitailOprations();
        }


        #endregion

        #region Properties

        public IEnumerable<PatientLinkModel> DisplayScheduledList
        {
            get
            {
                return _displayScheduledList;
            }

            set
            {
                _displayScheduledList = value;
                RaisePropertyChanged("DisplayScheduledList");
            }
        }

        public string CurRoomText
        {
            get
            {
                return _curRoomText;
            }

            set
            {
                _curRoomText = value;
                RaisePropertyChanged("CurRoomText");
            }
        }

        public PatientLinkModel SelectedP
        {
            get
            {
                return _selectedP;
            }

            set
            {
                if (value == null) return;
                SecheduleMainCtrlViewModel.Instance.SelectedSechduledP = value;
                RaisePropertyChanged("SelectedP");
            }
        }
     

        public IEnumerable<PatientLinkModel> ScheduledList
        {
            get
            {
                return _scheduledList;
            }

            set
            {
                _scheduledList = value;
            }
        }
        
       

        public string Hospital_code
        {
            get
            {
                return hospital_code;
            }

            set
            {
                hospital_code = value;
                RaisePropertyChanged("Hospital_code");
            }
        }

        #endregion

        #region Event

        #endregion

        #region Private Methods

        private void InitCurRoom()
        {
            if (SecheduleMainCtrlViewModel.Instance.CurrentRoom!=null)
            {
                CurRoomText = SecheduleMainCtrlViewModel.Instance.CurrentRoom.ConfigOperationRoomModel.Name + "号——手术间";
            }
            else
            {
                CurRoomText = "未选择手术间!";
            }
        }

        private void InitData()
        {
            try
            {
                if (SecheduleMainCtrlViewModel.Instance.CurrentRoom == null) return;
                ChangeRightCollection();
            }
            catch (Exception ex)
            {
                Common.LogHelper.Error("PaiTaiMainViewModel", ex);
            }
        }

        

        #endregion

        #region Public/Protected Methods
        public override void Refresh()
        {
            InitData();
        }

        public void ChangeRightCollection()
        {
            DisplayScheduledList = SecheduleMainCtrlViewModel.Instance.GetSechduledByRoomId();
            InitCurRoom();
        }

        #endregion

        #region EventHandlers

        #endregion


        #region Command

        #region ChangeDoctorCommand


        #endregion

        #region OpenPopupCommand

        #endregion
        #endregion


    }
}
